package com.xcity.record;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.xcity.merge.MergeUtil;

public class Ranking extends BaseRecord {
	public static String SQL_PARA = "playerId, type, value, time";

	public static String COUNT_SQL = "select count(id) from ranking {0}";
	public static String SELECT_LIMIT = "select * from ranking {2} limit {0},{1}";
	public static String CONDITION = "WHERE ranking.playerId not IN (SELECT player.id FROM player WHERE player.vipLvl = {0} AND player.`level` < {1} AND player.lastLoginTime < \"{2}\")";
	
	protected long playerId;
	protected byte type;
	protected long value;
	protected long time;
	
	@Override
	public void load(ResultSet rs) throws SQLException {
		this.playerId = rs.getLong(2);
		this.type = rs.getByte(3);
		this.value = rs.getLong(4);
		this.time = rs.getLong(5);
	}

	@Override
	public String getColumnNames() {
		return SQL_PARA;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(MergeUtil.toSqlString(playerId));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(type));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(value));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(time));
		return sb.toString();
	}
	
	@Override
	public String toSqlString(){
		switch (status) {
		case STATUS_INSERT:
		{
			StringBuffer sb = new StringBuffer();
			sb.append("INSERT INTO `");
			String tableName = getClass().getSimpleName().toLowerCase();
			sb.append(tableName);
			sb.append('`');
			sb.append(" (");
			sb.append(getColumnNames());
			sb.append(")");
			sb.append(" VALUES (");
			sb.append(toString());
			sb.append(");\n");
			return sb.toString();
		}
	}
	return "";
}

}
